package top.jiangqiang.qianyi.common.storage.config;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import org.dromara.hutool.core.text.StrUtil;
import top.jiangqiang.qianyi.common.constants.http.HttpProtocol;
import top.jiangqiang.qianyi.common.storage.base.BaseStorageConfig;

import java.io.Serial;
import java.io.Serializable;

/**
 * @Date 2024/7/5 下午4:48
 * @Author Jiangqiang
 */
@Data
@Schema(name = "存储器属性配置", description = "")
public class S3StorageConfig extends BaseStorageConfig implements Serializable {
    @Serial
    private static final long serialVersionUID = 1L;
    /**
     * 存储器名，多个配置不可重复
     */
    @Schema(description = "存储器名，多个配置不可重复")
    private String name;
    /**
     * region
     */
    @Schema(description = "region", example = "ap-beijing", defaultValue = "Auto")
    private String region = "Auto";
    /**
     * 上传时endpoint所使用的协议，会拼接在endpoint的前面
     */
    @Schema(description = "上传时endpoint所使用的协议，会拼接在endpoint的前面", defaultValue = "HTTPS")
    private HttpProtocol endpointProtocol = HttpProtocol.HTTPS;
    /**
     * 文件最终访问链接使用的协议，例如：HTTPS
     */
    @Schema(description = "文件最终访问链接使用的协议", defaultValue = "HTTPS")
    private HttpProtocol accessProtocol = HttpProtocol.HTTPS;
    /**
     * accessKey，例如：LTAI5tQEFJNuUjDX9D1A22Ac
     */
    @Schema(description = "accessKey", example = "LTAI5tQEFJNuUjDX9D1A22Ac")
    @NotBlank(message = "keyId不能为空")
    private String accessKey;
    /**
     * accessSecret，例如：JtjQ2wnDSKjzuzdRdLBf6z1y5DjkA1
     */
    @Schema(description = "accessSecret", example = "JtjQ2wnDSKjzuzdRdLBf6z1y5DjkA1")
    @NotBlank(message = "accessSecret不能为空")
    private String accessSecret;
    /**
     * 访问风格，由于整个对象是List中的一个元素，所以yaml配置文件中需要添加引号，否则无法注入
     */
    @Schema(description = "访问风格")
    @NotNull(message = "访问风格不能为空")
    private Boolean enablePathStyleAccess = true;
    /**
     * 域名
     */
    @Schema(description = "域名")
    private String domain;
    /**
     * bucket
     */
    @Schema(description = "bucket")
    private String bucket;
    /**
     * endpoint，腾讯云参考：https://www.tencentcloud.com/zh/document/product/436/6224，例如：oss-cn-chengdu.aliyuncs.com
     */
    @Schema(description = "endpoint，腾讯云参考：https://www.tencentcloud.com/zh/document/product/436/6224", example = "oss-cn-chengdu.aliyuncs.com")
    @NotBlank(message = "endpoint不能为空")
    private String endpoint;
    /**
     * 上传到指定文件夹内，中间可以包含/，但是不应该以/开头或结束
     */
    @Schema(description = "上传到指定文件夹内")
    private String dirName;

    @Override
    public String uniqueStr() {
        return StrUtil.concat(true, getName(), name, region, bucket, endpoint, dirName);
    }
}
